package com.zqwm.fly.http;

import org.springframework.stereotype.Controller;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;

@Controller
public class InvitationController
{
    @RequestMapping("/invitation")
    public String reader()
    {
        return "ftl/invitation/index";
    }

    @RequestMapping("/invitation1")
    public String reader1()
    {
        return "ftl/invitation/index1";
    }

    @RequestMapping("/getData")
    @ResponseBody
    public String getData(HttpServletRequest request, HttpServletResponse response) throws Exception
    {
        StringBuffer sb = new StringBuffer();
        //File file = ResourceUtils.getFile("classpath:static/data.json");
        //InputStream in = new FileInputStream(file);

        InputStream in =this.getClass().getClassLoader().getResourceAsStream("static/data.json");

        BufferedReader br = new BufferedReader(new InputStreamReader(in,"utf-8"));// 读取原始json文件

        String s = null;
        while ((s = br.readLine()) != null) {
            sb.append(s);
        }
        br.close();

        return sb.toString();
    }

    @RequestMapping("/getData1")
    @ResponseBody
    public String getData1(HttpServletRequest request, HttpServletResponse response) throws Exception
    {
        StringBuffer sb = new StringBuffer();
        //File file = ResourceUtils.getFile("classpath:static/data.json");
        //InputStream in = new FileInputStream(file);

        InputStream in =this.getClass().getClassLoader().getResourceAsStream("static/data1.json");

        BufferedReader br = new BufferedReader(new InputStreamReader(in,"utf-8"));// 读取原始json文件

        String s = null;
        while ((s = br.readLine()) != null) {
            sb.append(s);
        }
        br.close();

        return sb.toString();
    }
}
